//
//  ViewController.swift
//  IOSQnPlayerLib
//
//  Created by wrs on 10/28/2025.
//  Copyright (c) 2025 wrs. All rights reserved.
//

import UIKit
import QNRTPlayerKit

class ViewController: UIViewController, QNRTPlayerDelegate {

    @IBOutlet weak var containerView: UIView!
    var player: QNRTPlayer?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.player = QNRTPlayer()
        self.player?.delegate = self
        if let v = self.player?.playView {
            v.superview
            self.containerView.addSubview(v)
            v.frame = self.containerView.bounds
        }
        var urlStr = "webrtc://livecyz.chaoezu.top:447/chaoezu/wawaji10"
//        urlStr = "webrtc://qvs-live.ezhua.top:447/ezhua/ezhua1"
//        urlStr = "rtmp://livecyz.chaoezu.top:2045/chaoezu/wawaji10"
        urlStr = "https://v2.tlkqc.com/202505/23/J2dwuThNJ074/video/index.m3u8"
        if let url = URL(string: urlStr) {
            self.player?.play(with: url, supportHttps: true)
        }
    
    
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // QNRTPlayerDelegate
    func rtPlayer(_ player: QNRTPlayer, didFailWithError error: any Error) {
        print("didFailWithError: \(error.localizedDescription)")
    }
    
    func rtPlayer(_ player: QNRTPlayer, playStateDidChange playState: QNRTPlayState) {
        
    }
    
    func rtPlayer(_ player: QNRTPlayer, didGetStatistic statistic: [AnyHashable : Any]) {
        
    }
    
    
    func rtPlayer(_ player: QNRTPlayer, trackDidReceived kind: QNRTSourceKind) {
        
    }
    
    func rtPlayer(_ player: QNRTPlayer, firstSourceDidDecode kind: QNRTSourceKind) {
        
    }
    

    func rtPlayer(_ player: QNRTPlayer, didStartPictureInPicture pictureInPictureController: AVPictureInPictureController) {
        
    }
    
    func rtPlayer(_ player: QNRTPlayer, didStopPictureInPicture pictureInPictureController: AVPictureInPictureController) {
        
    }
    
    
    func rtPlayer(_ player: QNRTPlayer, restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void) {
        
    }
}

